const BASE_URL = 'http://codercba.com:9060/oppo-nuxt/api'

class HYRequst {
	request(url, methods, data, options) {
		return new Promise((resolve, reject) => {
			const newOptions = {
				baseURL: BASE_URL,
				method: methods,
				...options,
			}

			if (methods === 'GET') {
				newOptions.query = data
			}

			if (methods === 'POST') {
				newOptions.body = data
			}

			useFetch(url, newOptions)
				.then((res) => {
					resolve(res)
				})
				.catch((error) => {
					reject(error)
				})
		})
	}

	get(url, params, options) {
		return this.request(url, 'GET', params, options)
	}

	post(url, data, options) {
		return this.request(url, 'POST', data, options)
	}
}

export default new HYRequst()
